package cn.sjtu.algorithm.union_search_set;

import java.util.Scanner;

/**
 * @author syo 2319615164@qq.com
 * @description 合并集合
 * @date 2024/5/16
 * @Copyright syo
 */
// https://www.acwing.com/problem/content/838/
public class AcWing836 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        in.nextLine();
        UnionSearchSet set = new UnionSearchSet(n);
        for (int i = 0; i < m; i++) {
            String[] params = in.nextLine().split(" ");
            String op = params[0];
            int a = Integer.parseInt(params[1]);
            int b = Integer.parseInt(params[2]);

            if ("M".equals(op)) {
                set.union(a, b);
            } else {
                int p1 = set.find(a);
                int p2 = set.find(b);
                System.out.println(p1 == p2 ? "Yes" : "No");
            }
        }
    }
}
